package main;

import java.awt.*;

import static main.Game.k;
import static main.Player.*;
import static main.Register.PLAYER;
import static main.Register.WALLS;

public class AbstractEntity {
    public double width = 32;
    public double height = 32;
    public double posX;
    public double posY;
    public final Image image;
    public double boxX1;
    public double boxY1;
    public double boxX2;
    public double boxY2;
    public int turn;
    public double toPosX = 0;
    public double toPosY = 0;

    public AbstractEntity(Image image) {
        this.image = image;
    }
    public void setPos (int x, int y) {
        posX = x;
        posY = y;
    }





    public void update() {


//        int stepx = 0;
//        int stepy = 0;
//
//
//        for (AbstractEntity wall : WALLS) {
//            if (posX + this.getWidth()-1 + stepx < wall.getX1()
//                    || posX + stepx+1 > wall.getX2()
//                    || posY + this.getHeight()-1 + stepy < wall.getY1()
//                    || posY + stepy+1 > wall.getY2()
//            ) {
//                posX += stepx;
//                posY += stepy;
//            }
//        }
    }
    public void draw(Graphics g) {
        g.drawImage(image, (int) posX, (int) posY, (int) (posX+32), (int) (posY+32),
                0,0, image.getWidth(null), image.getHeight(null),
                null);
    }


    public void draw(Graphics g, int x1,int y1, int x2,int y2) {
//        g.drawImage(image,x1,y1,null);
        for (int y = y1; y < y2; y+=32) {
            for (int x = x1; x < x2; x+=32) {
                g.drawImage(image,
                        (int) (Game.WIDTH / 2 + (x- PLAYER.posX) * k),
                        (int) (Game.HEIGHT / 2 + (y - PLAYER.posY) * k),
                        (int) ( (Game.WIDTH / 2 + (x - PLAYER.posX) * k) + this.width),
                        (int) ( (Game.HEIGHT / 2 + (y - PLAYER.posY) * k) + this.height),
                        0, 0,
                        image.getWidth(null),
                        image.getHeight(null),
                        null);
            }
        }
    }
    public void drawPartAnimation (Graphics g, Image image) {
        g.drawImage(image,
                (int) (Game.WIDTH / 2 + (this.posX-width/2 - PLAYER.posX) * k),
                (int) (Game.HEIGHT / 2 + (this.posY-height/2 - PLAYER.posY) * k),
                (int) (Game.WIDTH / 2 + (this.posX+width/2 - PLAYER.posX) * k),
                (int) (Game.HEIGHT / 2 + (this.posY+height/2 - PLAYER.posY) * k),
                0,0, image.getWidth(null), image.getHeight(null),
                null);
    }

    public void setBox(double x1,double y1, double x2,double y2) {
        boxX1 = x1;
        boxY1 = y1;
        boxX2 = x2;
        boxY2 = y2;
    }


}
